package com.clouddisk.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.clouddisk.common.core.domain.dto.sharefile.ShareCancelFileDTO;
import com.clouddisk.common.core.domain.dto.sharefile.ShareListDTO;
import com.clouddisk.common.core.domain.entity.Share;
import com.clouddisk.system.domain.vo.share.ShareListVO;
import com.clouddisk.system.mapper.ShareMapper;
import com.clouddisk.system.service.IShareService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@RequiredArgsConstructor
@Service
public class ShareServiceImpl extends ServiceImpl<ShareMapper, Share> implements IShareService {

    @Resource
    ShareMapper shareMapper;

    @Override
    public List<ShareListVO> selectShareList(ShareListDTO shareListDTO, Long userId) {
        Long beginCount = (shareListDTO.getCurrentPage() - 1) * shareListDTO.getPageCount();
        return shareMapper.selectShareList(shareListDTO.getShareFilePath(),
                shareListDTO.getShareBatchNum(),
                shareListDTO.getFileDeptName(),
                beginCount, shareListDTO.getPageCount(),userId);
    }

    @Override
    public int selectShareListTotalCount(ShareListDTO shareListDTO, Long userId) {
        return shareMapper.selectShareListTotalCount(
            shareListDTO.getShareFilePath(), shareListDTO.getShareBatchNum(), shareListDTO.getFileDeptName(),userId);
    }

    @Override
    public void selectCancelShareList(ShareCancelFileDTO shareCancelFileDTO, Long userId){
        // 更新取消的分享
        LambdaUpdateWrapper<Share> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(Share::getShareId,shareCancelFileDTO.getShareId())
            .set(Share::getShareStatus,2);
        shareMapper.update(null, lambdaUpdateWrapper);
    }

}
